package lamma.lab2.job;

import java.util.Arrays;
import java.util.List;

import junit.framework.Assert;
import lamma.lab2.job.JobExecutor.BatchParam;
import lamma.lab2.job.JobExecutor.BatchResult;
import lamma.test.helper.FutureHelper;

import org.junit.Test;

public class BatchJobTest2 {

	private static class Job1 {
		@SuppressWarnings("unused")
		List<String> inputs;
		
		BatchParam<String> param;

		@ProvidedBy(job=Job2.class, params="param", result="result")
		BatchResult<String> output;
		
		Job1(List<String> inputs) {
			this.inputs = inputs;
			this.param = new BatchParam<String>();
			
			for (String input : inputs) {
				param.addParam(input);
			}
		}
		
	}
	
	private static class Job2 {
		
		String input;
		
		@SuppressWarnings("unused")
		@AfterStep("step2")
		String result;

		@SuppressWarnings("unused")
		Job2(String input) {
			super();
			this.input = input;
		}
		
		@SuppressWarnings("unused")
		@Step
		AsyncStep step() {
			return AsyncStep.Builder.fromFuture(FutureHelper.mockFuture(100, null));
		}
		
		@SuppressWarnings("unused")
		@Step(steps="step")
		void step2() {
			this.result = this.input + "r";
		}
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	public void test() {
		Job1 job1 = new Job1(Arrays.asList("a", "b", "c", "d"));
		
		new JobExecutor(job1).go();
		
		BatchResult<String> result = job1.output;
		
		Assert.assertNotNull(result);
		Assert.assertEquals("ar", result.lookupResult("a"));
		Assert.assertEquals("br", result.lookupResult("b"));
		Assert.assertEquals("cr", result.lookupResult("c"));
		Assert.assertEquals("dr", result.lookupResult("d"));
	}
}
